home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Dr. Windows 3
/
dr win3.zip
/
dr win3
/
PROGRAMR
/
OLE2BOOK.ZIP
/
CHAP08.ZIP
/
CHAP08
/
PATRON
/
PAGES.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
1993-06-07
|
27KB
|
1,204 lines
/*
* PAGES.CPP
* Modifications for Chapter 8
*
* Implementation of the CPages class. See PAGEWIN.CPP for additional
* member functions.
*
* Copyright (c)1993 Microsoft Corporation, All Rights Reserved
*
* Kraig Brockschmidt, Software Design Engineer
* Microsoft Systems Developer Relations
*
* Internet : kraigb@microsoft.com
* Compuserve: >INTERNET:kraigb@microsoft.com
*/
#include "patron.h"
HWND g_hDlgPrint=NULL;
BOOL g_fCancelPrint=FALSE;
/*
* CPages:CPages
* CPages::~CPages
*
* Constructor Parameters:
* hInst HINSTANCE of the application we're in.
* cf UINT application clipboard format.
*/
CPages::CPages(HINSTANCE hInst, UINT cf)
: CWindow(hInst)
{
m_pPageCur=NULL;
m_iPageCur=0xFFFF; //Pages are 0 indexed, so this is one before that.
m_cPages=0;
m_hWndPageList=NULL;
/*
* Initialize to 2.54cm*2.54cm which is a page with no space for anything,
* just margins. 2.54cm=.5 inches on each margin.
*/
m_cx=LOMETRIC_PER_INCH;
m_cy=LOMETRIC_PER_INCH;
m_xPos=0L;
m_yPos=0L;
m_dwIDNext=0;
m_pIStorage=NULL;
m_fDirty=FALSE;
m_cf=cf;
//CHAPTER8MOD
m_fDragSource=FALSE;
m_fMoveInPage=FALSE;
m_fDragRectShown=FALSE;
m_uScrollInset=GetProfileInt("windows", "DragScrollInset", DD_DEFSCROLLINSET);
m_uScrollDelay=GetProfileInt("windows", "DragScrollDelay", DD_DEFSCROLLDELAY);
m_uHScrollCode=0;
m_uVScrollCode=0;
//End CHAPTER8MOD
return;
}
CPages::~CPages(void)
{
//Insure memory is cleaned up in list, and do final IStorage::Release
FIStorageSet(NULL, FALSE, FALSE);
if (NULL!=m_hFont && !m_fSystemFont)
DeleteObject(m_hFont);
if (NULL!=m_hWndPageList)
DestroyWindow(m_hWndPageList);
//m_hWnd destroyed with the document.
return;
}
/*
* CPages::FIsDirty
*
* Purpose:
* Tells the caller (document) if anything's happened to dirty us.
*
* Parameters:
* None
*
* Return Value:
* None
*/
BOOL CPages::FIsDirty(void)
{
return m_fDirty;
}
/*
* CPages::FInit
*
* Purpose:
* Instantiates a pages window within a given parent. The
* parent may be a main application window, could be an MDI child
* window. We really do not care.
*
* Parameters:
* hWndParent HWND of the parent of this window
* pRect LPRECT that this window should occupy
* dwStyle DWORD containing the window's style flags. Should
* contain WS_CHILD | WS_VISIBLE in typical circumstances.
* uID UINT ID to associate with this window
* pv LPVOID unused for now.
*
* Return Value:
* BOOL TRUE if the function succeeded, FALSE otherwise.
*/
BOOL CPages::FInit(HWND hWndParent, LPRECT pRect, DWORD dwStyle
, UINT uID, LPVOID pv)
{
int cy;
m_hWnd=CreateWindowEx(WS_EX_NOPARENTNOTIFY, SZCLASSPAGES
, SZCLASSPAGES, dwStyle, pRect->left, pRect->top
, pRect->right-pRect->left, pRect->bottom-pRect->top
, hWndParent, (HMENU)uID, m_hInst, (LPVOID)this);
if (NULL==m_hWnd)
return FALSE;
/*
* Create the hidden listbox we'll use to track pages. We give it
* the owner-draw style so we can just store pointers in it. We have
* to set the parent to NULL such that the window hangs around after
* the pages window is destroyed so that we can clean up the
* memory stored in it from the CPages destructor.
*/
m_hWndPageList=CreateWindow("listbox", "Page List", WS_POPUP | LBS_OWNERDRAWFIXED
, 0, 0, 100, 100, HWND_DESKTOP, NULL, m_hInst, NULL);
if (NULL==m_hWndPageList)
return FALSE;
//Create a 14 point Arial font, or use the system variable font.
cy=MulDiv(-14, LOMETRIC_PER_INCH, 72);
m_hFont=CreateFont(cy, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE
, ANSI_CHARSET, OUT_TT_PRECIS, CLIP_TT_ALWAYS, PROOF_QUALITY
, VARIABLE_PITCH | FF_SWISS, "Arial");
if (NULL==m_hFont)
{
m_hFont=(HFONT)GetStockObject(ANSI_VAR_FONT);
m_fSystemFont=TRUE;
}
return TRUE;
}
/*
* CPages::FIStorageSet
*
* Purpose:
* Provides the document's IStorage to the pages for its own uses.
* If this is a new storage, then we initalize it with streams we
* want to always exists. If this is an open, then we create
* our page list from the PageList string we wrote before.
*
* Parameters:
* pIStorage LPSTORAGE to the new or opened storage. If this is
* NULL then we just clean up and exit.
* fChange BOOL indicating is this was a Save As operation
* meaning that we have the structure already, we
* just need to change our value of m_pIStorage.
* fInitNew BOOL indicating if this is a new storage or one
* opened from a previous save.
*
* Return Value:
* None
*/
BOOL CPages::FIStorageSet(LPSTORAGE pIStorage, BOOL fChange, BOOL fInitNew)
{
DWORD dwMode=STGM_DIRECT | STGM_READWRITE | STGM_SHARE_EXCLUSIVE;
HRESULT hr;
LPPAGE pPage;
BOOL fRet=FALSE;
ULONG cbRead;
PAGELIST pgList;
LPSTREAM pIStream;
LPMALLOC pIMalloc;
LPDWORD pdwID;
UINT i;
//If we're just changing saved roots, just open the current page again
if (fChange)
{
if (NULL==pIStorage)
return FALSE;
m_pIStorage->Release();
m_pIStorage=pIStorage;
m_pIStorage->AddRef();
FPageGet(m_iPageCur, &m_pPageCur, TRUE);
return TRUE;
}
if (NULL!=m_hWndPageList)
{
//On new or open, clean out whatever it is we have.
for (i=0; i < m_cPages; i++)
{
if (FPageGet(i, &pPage, FALSE))
delete pPage;
}
SendMessage(m_hWndPageList, LB_RESETCONTENT, 0, 0L);
}
if (NULL!=m_pIStorage)
m_pIStorage->Release();
m_pIStorage=NULL;
//If we're just cleaning up, then we're done.
if (NULL==pIStorage)
return TRUE;
m_pIStorage=pIStorage;
m_pIStorage->AddRef();
//If this is a new storage, create the streams we require
if (fInitNew)
{
//Page list header.
hr=m_pIStorage->CreateStream(SZSTREAMPAGELIST, dwMode | STGM_CREATE
, 0, 0, &pIStream);
if (FAILED(hr))
return FALSE;
pIStream->Release();
//Device Configuration
hr=m_pIStorage->CreateStream(SZSTREAMDEVICECONFIG, dwMode | STGM_CREATE
, 0, 0, &pIStream);
if (FAILED(hr))
return FALSE;
pIStream->Release();
return TRUE;
}
/*
* We're opening an existing file:
* 1) Configure for the device we're on
* 2) Read the Page List and create page entries for each.
*/
ConfigureForDevice();
//Read the page list.
hr=m_pIStorage->OpenStream(SZSTREAMPAGELIST, NULL, dwMode, 0, &pIStream);
if (FAILED(hr))
return FALSE;
if (SUCCEEDED(CoGetMalloc(MEMCTX_SHARED, &pIMalloc)))
{
pIStream->Read((LPVOID)&pgList, sizeof(PAGELIST), &cbRead);
m_cPages =(UINT)pgList.cPages;
m_iPageCur=(UINT)pgList.iPageCur;
m_dwIDNext=pgList.dwIDNext;
fRet=TRUE;
cbRead=pgList.cPages*sizeof(DWORD);
if (0!=cbRead)
{
pdwID=(LPDWORD)pIMalloc->Alloc(cbRead);
if (NULL!=pdwID)
{
pIStream->Read((LPVOID)pdwID, cbRead, &cbRead);
for (i=0; i < m_cPages; i++)
fRet &=FPageAdd(-1, *(pdwID+i), FALSE); //-1==end of list
pIMalloc->Free((LPVOID)pdwID);